package com.example.aopproxy.component;

import com.example.aopproxy.demo.StudentDo;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class UserAspect {

    @Autowired
    private Student student;

    /**
     * 切点：配置拦截规则
     */
    @Pointcut("execution(* com.example.aopproxy.controller.UserController.study())")
    public void pointcut() {
    }

    /**
     * 前置通知
     */
    @Before("pointcut()")
    public void beforeAdvice() {
        student.listening();
    }

    /**
     * 后置通知
     */
    @After("pointcut()")
    public void aftereAdvice() {
        student.classClose();
    }

    /**
     * 环绕通知
     * @param joinPoint
     * @return
     * @throws Throwable
     */
    @Around("pointcut()")
    public Object aroundAdvice(ProceedingJoinPoint joinPoint) throws Throwable {
        student.readClass();
        Object obj = null;
        obj = joinPoint.proceed();
        return obj;
    }

}
